<?php


namespace app\backend\controller;


use app\base\controller\AdminBaseController;
use think\Exception;
use think\facade\Request;
use think\facade\View;

class Permission extends AdminBaseController
{
    public function index(){
        $typeList = \app\common\model\Permission::order(['id'=>'desc'])->paginate(15,false);

        $this->assign('list',$typeList);
        $this->assign('page',$typeList->render());
        return View::fetch();
    }
    public function add(){
        return View::fetch();
    }
    public function edit($id){

        $id = Request::param('id',0);
        if(empty($id)|| !is_numeric($id+0)){throw new Exception('数据错误');}
        $typeInfo = \app\common\model\Permission::where('id',$id)->find()->toArray();
        if(!$typeInfo){throw new Exception('数据错误');}

        View::assign('typeInfo',$typeInfo);

        return View::fetch();
    }
    public function delete($id){
        $id = Request::param('id',0);
        if(empty($id)|| !is_numeric($id+0)){wapAjaxReturn(400);}

        $info = \app\common\model\Permission::get($id);
        $info->delete();
        wapAjaxReturn(0);
    }


    public function deal(){
        $request = Request::post();

        $type = new \app\common\model\Permission();


        $type->deal($request);
    }
}